package utool

import (
	"your-tool/internal/define"
	"your-tool/internal/service"
)

func (a *App) MenuList() H {
	m, err := service.GetMenuList()
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
		"data": m,
	}
}

// 获取时间线列表
func (a *App) TimeLineListGo() H {
	m, err := service.TimeLineList()
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
		"data": m,
	}
}

// 新增时间线
func (a *App) TimeLineCreateGo(timeLine *define.TimeLine) H {
	err := service.TimeLineCreate(timeLine)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
	}
}

// 查询时间线
func (a *App) TimeLineItemGo(identify string) H {
	m, err := service.TimeLineItem(identify)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
		"data": m,
	}
}

// 修改时间线
func (a *App) TimeLineEditGo(timeLine *define.TimeLine) H {
	err := service.TimeLineEdit(timeLine)
	if err != nil {
		return M{
			"code": 0,
			"msg":  err.Error(),
		}
	}
	return M{
		"code": 1,
		"msg":  "success",
	}
}
